package com.cutJar.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
 * <b>输出一个类的构造方法和成员方法</b>
 * <p>
 * 描述:<br>
 * 
 * @author 威 
 * <br>2018年4月16日 下午7:50:51 
 * @see
 * @since 1.0
 */
public class ClassInformation {
	public int num;
	public static void main(String[] args) throws ClassNotFoundException{
		//Class<?> clazzProxy = Proxy.getProxyClass(java.util.Collection.class.getClassLoader()) ;
		getClassInfor(ClassInformation.class);
	}
	@SuppressWarnings("rawtypes")
	public static void getClassInfor(Class<?> clazz){
		Class<?> clazzProxy = clazz;
		System.out.println("----------------- fileds -----------------");
		Field[] fields =  clazzProxy.getFields();
		for(Field field : fields){
			StringBuilder fieldString = new StringBuilder() ;
			fieldString.append(field.getType()).append(" ").append(field.getName());
			System.out.println(fieldString);
		}
		System.out.println("-------------- constroctors --------------");
		
		Constructor[] constructors = clazzProxy.getConstructors() ;
		for(Constructor constructor : constructors){
			StringBuilder sb = new StringBuilder() ;
			sb.append(clazzProxy.getSimpleName() + "(");
			Class<?>[] parameterTypes = constructor.getParameterTypes() ;
			for(Class parameterType : parameterTypes){
				sb.append(parameterType.getSimpleName() + ",");
			}
			if(parameterTypes != null & parameterTypes.length != 0)
				sb.deleteCharAt(sb.length()-1);
			sb.append(")");
			System.out.println(sb.toString());
		}
		System.out.println("----------------- selfmethods ----------------");
		Method[] methodsDeclare = clazzProxy.getDeclaredMethods();
		for(Method method : methodsDeclare){
			StringBuilder sb = new StringBuilder() ;
			sb.append(method.getName() + "(");
			Class<?>[] parameterTypes = method.getParameterTypes() ;
			for(Class parameterType : parameterTypes){
				sb.append(parameterType.getSimpleName() + ",");
			}
			if(parameterTypes != null & parameterTypes.length != 0)
				sb.deleteCharAt(sb.length()-1);
			sb.append(")");
			System.out.println(sb.toString());
		}
		
		System.out.println("----------------- methods ----------------");
		Method[] methods = clazzProxy.getMethods();
		for(Method method : methods){
			StringBuilder sb = new StringBuilder() ;
			sb.append(method.getName() + "(");
			Class<?>[] parameterTypes = method.getParameterTypes() ;
			for(Class parameterType : parameterTypes){
				sb.append(parameterType.getSimpleName() + ",");
			}
			if(parameterTypes != null & parameterTypes.length != 0)
				sb.deleteCharAt(sb.length()-1);
			sb.append(")");
			System.out.println(sb.toString());
		}
	}
}
